from time import sleep
import unittest,random,sys
sys.path.append("./models")
sys.path.append("./page_obj")
from models import myunit,function
from page_obj.loginPage import Login

class loginTest(myunit.MyTest):
    '''京东登录测试'''
    #测试用户登录
    def user_login_verify(self,username="",password=""):
        Login(self.driver).user_login(username,password)
    #用户名和密码为空登录
    def test_login1(self):
        self.user_login_verify()
        po = Login(self.driver)
        self.assertEqual(po.user_error_hint(),"账号不能为空")
        self.assertEqual(po.pawd_error_hint(), "密码不能为空")
        function.insert_img(self.driver,"user_pawd_empty.jpg")
    #用户名正确，密码为空登录
    def test_login2(self):
        self.user_login_verify(username="15216707828")
        po = Login(self.driver)
        self.assertEqual(po.pawd_error_hint(), "密码不能为空")
        function.insert_img(self.driver, "pawd_empty.jpg")
    #用户名为空，密码正确
    def test_login3(self):
        self.user_login_verify(password="15216707828ll")
        po = Login(self.driver)
        self.assertEqual(po.user_error_hint(), "账号不能为空")
        function.insert_img(self.driver, "user_empty.jpg")
    def test_login4(self):
        character = random.choice("defjsjkfeiowfhcbsowriowhrbcks")
        username = "zhangsan"+character
        self.user_login_verify(username=username,password="15216707828ll")
        po = Login(self.driver)
        self.assertEqual(po.pawd_error_hint(), "密码与账号不匹配")
        function.insert_img(self.driver, "user_pawd_error.jpg")
    #用户名与密码均正确
    def test_login5(self):
        self.user_login_verify(username="15216707828",password="15216707828ll")
        sleep(2)
        po = Login(self.driver)
        self.assertEqual(po.use_login_success(), "15216707828")
        function.insert_img(self.driver, "user_pawd_true.jpg")
if __name__ == '__main__':
    unittest.main()
